﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
namespace AsteroidWar
{
    class DemoManager
    {
        Video video;
        VideoPlayer videoPlayer;
        Viewport viewport;
        Texture2D videoTexture;
        public bool isStoped = false;
        public DemoManager(ContentManager contentManager, Viewport viewport)
        {
           this.viewport =viewport;
           video = contentManager.Load<Video>(@"Videos\demo");
           videoPlayer = new VideoPlayer();
           videoPlayer.IsLooped = false;
        }
        public void stop()
        {
            videoPlayer.Stop();
        }
        public void PlayDemo()
        {
            videoPlayer.Play(video);        
        }

        public void Update(GameTime gameTime)
        {
            if (videoPlayer.State == MediaState.Stopped)
            {
                if (!isStoped)
                {
                    videoPlayer.Play(video);
                    isStoped = true;
                }
                else
                {
                    isStoped = false;
                }
                
            }  
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            // Only call GetTexture if a video is playing or paused
            if (videoPlayer.State != MediaState.Stopped)
                videoTexture = videoPlayer.GetTexture();

            // Drawing to the rectangle will stretch the 
            // video to fill the screen
            Rectangle screen = new Rectangle(0,
                0,
                viewport.Width,
                viewport.Height);

            // Draw the video, if we have a texture to draw.
            if (videoTexture != null)
            {
                spriteBatch.Draw(videoTexture, screen, Color.White);
            }
        }
    }
}
